package cn.jiyun.utils;

import com.github.pagehelper.PageInfo;
import com.sun.corba.se.impl.interceptors.PICurrent;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

@Component
public class PageUtils<T> {


    public PageInfo<T> pageHaper(List<T> list, Integer pageNum, Integer pageSize){
        PageInfo<T> pageInfo = new PageInfo<>();
        List<T> page = list.stream()
                .skip((pageNum-1) * pageSize)     // 跳过前面的元素
                .limit(pageSize)                  // 限制元素数量
                .collect(Collectors.toList());
        pageInfo.setPageNum(pageNum);
        pageInfo.setPageSize(pageSize);
        pageInfo.setList(page);
        pageInfo.setTotal(list.size());
        return pageInfo;
    }
}
